package com.fangxing.module.user.controller;

import com.fangxing.module.user.bo.LoginBo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class AccountController {


    @RequestMapping("/login")
    public String login(LoginBo loginBo) {
        UsernamePasswordToken token = new UsernamePasswordToken(loginBo.getLoginName(), loginBo.getPassword());
        Subject currentUser = SecurityUtils.getSubject();

        currentUser.login(token);
        if (currentUser.isAuthenticated()) {
            Session session = currentUser.getSession();
            //Todo
        }

        return "";
    }

    @RequestMapping("/logout")
    public String logout(){
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();

        currentUser.logout();
        return "/index";
    }
}
